function upload({url,fileUri,fileInput="uploader"}) {
    let formData = new FormData();
    let file = {uri: fileUri, type: 'multipart/form-data', name: fileUri.split("/").pop()};
    formData.append(fileInput, file);
    return fetch(url, {
        method: 'POST',
        headers: {
            'Content-Type': 'multipart/form-data',
        },
        body: formData,
    })
        .then((response) => response.json())
}

const Tool={
    img(val){
        return "http://112.74.74.189/upload/"+val;
    },
    post(url,data){
        return fetch(url, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        }).then(data=> {
            return data.json()
        })
    },
    fetch(url){
        return fetch(url, {
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            }
        }).then(data=> {
            return data.json()
        })
    }
}

export {Tool}

export default upload;